;(function () {
    'use strict';
    //aes decode config
    const key = CryptoJS.enc.Utf8.parse("aaaabbbbccccdddd");
    const options={
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    };
    // 创建axios实例
    const fetch = axios.create({
        //测试地址
        baseURL: 'http://liveapi.fangpianz.com/live',
        timeout: 120000,
        headers: {
            'Content-Type':'application/json;charset=utf-8'
        }
    });
    // request拦截器
    fetch.interceptors.request.use(function(config){
        return config;
    }, function(error) {
        return Promise.reject(error);
    });

    // respone拦截器
    fetch.interceptors.response.use(function (response) {
        var res=response.data;
        if(response.status===200&&res.code==200&&res.data){
            var destr=CryptoJS.AES.decrypt(res.data, key, options).toString(CryptoJS.enc.Utf8);
            return JSON.parse(destr);
        }
        else {
            return Promise.reject(res);
        }
    }, function(e){
        return Promise.reject(e);
    });
    if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
        // AMD. Register as an anonymous module.
        define(function() {
            return fetch;
        });
    } else if (typeof module !== 'undefined' && module.exports) {
        module.exports.fetch =fetch;
    } else {
        window.fetch = fetch;
    }
}());